<?php
include_once("config.php");

function func_bw_volume_user_top10_periode($Start, $End){
	// Connect to server and select databse.
    global $host, $username, $password, $db_name;

	mysql_connect("$host", "$username", "$password")or die("cannot connect");
	mysql_select_db("$db_name")or die("cannot select DB");

	$sql="select client, sum(size) as size from logbook where Timestamp >= '$Start' and Timestamp <= '$End' group by Client limit 0, 10;";
    $result=mysql_query($sql);

    $bw = array(
            array('',0), array('',0), array('',0), array('',0),
            array('',0), array('',0), array('',0), array('',0),
            array('',0), array('',0));
    $i=0;
    while ($row = mysql_fetch_array($result)){
        $bw[$i][0] = $row['client'];
        $bw[$i][1] = round((($row['size'] /1024)/1024),1);

        $i++;
    }

    return $bw;
}

function func_bw_volume_user_all_periode($Start, $End){
	// Connect to server and select databse.
    global $host, $username, $password, $db_name;

	mysql_connect("$host", "$username", "$password")or die("cannot connect");
	mysql_select_db("$db_name")or die("cannot select DB");

	$sql="SELECT client, sum(size) as size, (SELECT count(DISTINCT domein) FROM logbook l WHERE client = logbook.client and Timestamp >= '$Start' and Timestamp <= '$End') as aantdom FROM `logbook` where Timestamp >= '$Start' and Timestamp <= '$End' GROUP BY client";
    $result=mysql_query($sql);


    return $result;
}

function func_bw_volume_user_all_periode_detail($Start, $End, $Client){
	// Connect to server and select databse.
    global $host, $username, $password, $db_name;

	mysql_connect("$host", "$username", "$password")or die("cannot connect");
	mysql_select_db("$db_name")or die("cannot select DB");

	$sql="SELECT domein, sum(size) as size FROM `logbook` where Client = '$Client' and Timestamp >= '$Start' and Timestamp <= '$End' GROUP BY domein";
    $result=mysql_query($sql);


    return $result;
}

?>